
import java.awt.Polygon;

import org.powerbot.core.script.job.Task;
import org.powerbot.core.script.job.state.Node;
import org.powerbot.game.api.methods.Game;
import org.powerbot.game.api.methods.Walking;
import org.powerbot.game.api.methods.interactive.NPCs;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.methods.widget.Camera;
import org.powerbot.game.api.wrappers.interactive.NPC;
import org.powerbot.game.api.wrappers.interactive.Player;


public class Fish extends Node{
	public static Polygon[] clickedSpot = null;
	public static boolean spotClicked = false;
	@Override
	public boolean activate() {
		// TODO Auto-generated method stub
		return !Inventory.isFull() && 
				!Fisher.dropping && !Fisher.banking && Game.isLoggedIn() && !Fisher.cooking ;
	}

	@Override
	public void execute() {
		// TODO Auto-generated method stub
		//fish
		//find closest pool and click.
		Player p = Players.getLocal();
		NPC spot = NPCs.getNearest(new int[]{330, 328});
		if(spot != null)
		{
			/*if(p.getAnimation() == -1)
			{
				if(spot.isOnScreen())
					spot.click(true);
				else
					Walking.walk(spot.getLocation());
			}*/
			if( clickedSpot != null)
			{
				if(p.getInteracting()!=null)
				{
					clickedSpot = p.getInteracting().getBounds();
				}
				else if(p.getAnimation() == -1)
					clickedSpot = null;
			}
			else
			{
				if(!spot.isOnScreen() && p.getAnimation() == -1)
				{
					Walking.walk(spot.getLocation());
					System.out.println("walking to spot");
				}
				else if(clickedSpot == null)
				{
					System.out.println("clicking spot");
					spot.click(true);
					clickedSpot = spot.getBounds();
					Task.sleep(300);
				}
			}
		}
		
	}

}
